from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage,HumanMessage

from langgraph.graph import MessageGraph

from typing import TypedDict,Annotated,List
import operator


api_key = "sk-6S0PtpNia71gjcfwSsDPsJ9mGqsVPr2XRQzAx1dHbJS7RW4t"
api_base="https://chatapi.littlewheat.com/v1"

llm = ChatOpenAI(model="gpt-4o",api_key=api_key,base_url=api_base)

class State(TypedDict):
    messages:Annotated[List[str],operator.add]

def chatbot(state:State):
    print(state)
    return {"messages":[llm.invoke(state["messages"])]}

builder = MessageGraph()

builder.add_node("chatbot",lambda state:[("assistant","你好，最帅气的人！")])
builder.set_entry_point("chatbot")
builder.set_finish_point("chatbot")

graph=builder.compile()
resp = graph.invoke([("user", "你好，请你介绍一下你自己.")])
print(resp)